package com.bstek.sample;


import com.bstek.bdf4.cache.core.manager.MultilevelCache;
import com.bstek.utils.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @Title: ApiDataController
 * @Package: com.bstek.bdf3.sample.controller
 * @Description:
 * @Author: zxq
 * @Date: 2023/11/13 - 10:31
 */

@RestController
@RequestMapping("/api/data")
@Slf4j
public class ApiDataController {
    @Resource
    private MultilevelCache multilevelCache;


    @GetMapping("/put/cache")
    public void put() {
        UserVO ds = new UserVO();
        ds.setName("多级缓存");
        ds.setId(1);
        ds.setCreateTime(TimestampUtil.current());
        multilevelCache.put("test-key", ds);
    }

    @GetMapping("/get/cache")
    public UserVO get() {
        UserVO userVO = multilevelCache.get("test-key", UserVO.class);
        if(userVO!=null){
            return userVO;
        }
        UserVO ds = new UserVO();
        ds.setName("数据库缓存");
        ds.setId(2);
        ds.setCreateTime(TimestampUtil.current());
        return ds;

    }
}
